package com.iee.file.io;

import org.springframework.util.ResourceUtils;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

/**
 *@ClassName classloader
 *@Description TODO
 *@Author longxiaonan@163.com
 *@Date 2021/5/14 0014 18:48
 */
public class classloader {

    public static void main(String[] args) throws IOException, URISyntaxException {
        // spring启动的时候调用ClassLoader获取到的URL异常
        // file:/E:/project/java-sea/javasea-base/target/classes/aa.properties
        URL systemResource = ClassLoader.getSystemResource("aa.properties");
        // file:/E:/project/java-sea/javasea-base/target/classes/aa.properties
        URL resource = ClassLoader.getSystemClassLoader().getResource("aa.properties");
        // file:/E:/project/java-sea/javasea-base/target/classes/
        URL systemResource1 = ClassLoader.getSystemResource("");
        // file:/E:/project/java-sea/javasea-base/target/classes/
        URL resource1 = ClassLoader.getSystemClassLoader().getResource("");

        // file:/E:/project/java-sea/aa.properties
        URL url = ResourceUtils.getURL("aa.properties");
        // file:/E:/project/java-sea/javasea-base/target/classes/aa.properties
        URL classPathUrl = ResourceUtils.getURL("classpath:aa.properties");
        // file:/E:/project/java-sea/
        URL url1 = ResourceUtils.getURL("");
        // 构建uri后读取配置
        URI uri = URI.create(systemResource.toString());
        System.out.println(uri);
        List<String> strings = Files.readAllLines(Paths.get(uri));
        System.out.println(strings);
    }

}
